package com.jianganming.bio.rpc.client;

import com.jianganming.bio.rpc.service.IHelloService;

import java.lang.reflect.Proxy;

public class RpcProxyClient {
    public <T> T clientProxy(Class<T> clazz,String host,int port){
        return (T)Proxy.newProxyInstance(
                clazz.getClassLoader(),
                new Class[]{clazz},
                new RemoteInvocationHandler(host,port));
    }

    public static void main(String[] args) {
        IHelloService service = new RpcProxyClient().clientProxy(IHelloService.class, "127.0.0.1", 8080);
        String s = service.sayHello("江安明");
        System.out.println(s);
    }
}
